local sk__youdi = fk.CreateSkill {

  name = "sk__youdi",

  tags = {},

}



sk__youdi:addEffect("viewas", {
  name = "sk__youdi",
  pattern = "jink",
  anim_type = "defensive",
  prompt = "#sk__youdi",
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    local card = Fk:cloneCard("jink")
    card.skillName = sk__youdi.name
    return card
  end,
  before_use = function(self, player, use)
    player:turnOver()
  end,
  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function(self, player, response)
    return not player.faceup
  end,
})

sk__youdi:addEffect(fk.CardEffectCancelledOut, {
  name = "#sk__youdi_trigger",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(sk__youdi.name) and target ~= player and data.to == player and data.card.trueName == "slash" and
        not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askForDiscard(player, 1, player:getHandcardNum(), true, "sk__youdi", true, ".",
      "#sk__youdi-invoke::" .. target.id, true)
    if #cards > 0 then
      event:setCostData(self, cards)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("sk__youdi")
    room:notifySkillInvoked(player, "sk__youdi", "control")
    room:doIndicate(player.id, { target.id })
    room:throwCard(event:getCostData(self), "sk__youdi", player, player)
    if player.dead or target.dead or target:isNude() then return end
    local n = #event:getCostData(self)
    local cards = room:askForCardsChosen(player, target, 1, n, "he", "sk__youdi",
      "#sk__youdi-discard::" .. target.id .. ":" .. n)
    room:throwCard(cards, "sk__youdi", target, player)
  end,
})

return sk__youdi
